package com.example.demo.controller;

import com.example.demo.domain.UserInfo;
import com.example.demo.feigns.UserFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private UserFeign userFeign;

    @GetMapping("/userInfo/{id}")
    public ResponseEntity<UserInfo> getUser(@PathVariable String id){
        UserInfo userInfo = userFeign.getUserInfo(id);
        System.out.println("product获取的用户信息: " + userInfo.toString());
        return ResponseEntity.ok(userInfo);
    }

    @PostMapping("/updateUser")
    public ResponseEntity<String> updateUser(@RequestBody UserInfo user){
        userFeign.updateUserInfo(user);
        System.out.println("product更新的用户信息: " + user.toString());
        return ResponseEntity.ok("更新成功");
    }
}
